<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="/js/jquery-3.2.1.min.js"></script>
</head>

<body>

	<div>
		<label>请输入长网址:ַ:</label>
		<input type="text" name="text" id="text">
		<button type="button" id="button" onclick="shortUrl()">缩短网址ַ</button>
		<br/>
		<label>缩短网址内容:</label>
		<input type="text" name="result" id="result" readonly="true">
		<button type="button" id="button" onclick="sendDirct()" >点击预览ַ</button>
	</div>
</body>
<script>

function shortUrl(){
	var path=$("#text").val();
	if(path==null||path==""){
		return;
	}
	$.ajax({
    	url: "/url/encript",
    	data: {
    	url:path
    	},
    	success: function (data) {
    	$("#result").val(data['data']);
   	    }
    });
}

function sendDirct(){
	var path=$("#result").val();
	if(path==null||path==""){
		return;
	}
	$.ajax({
    	url: "/url/sendDirct",
    	data: {
    	url:path
    	},
    	success: function (data) {
    		if(data['code']==200){
    			window.open(data['data']);
    		}
   	    }
    });
}


</script>
</html>